package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){
        // 分页(高级查询)
        Page<Destination> page = destinationService.queryForList(qo);
        model.addAttribute("page",page);
        // 通过父节点id查询对应的子对象,返回来一个对象集合
        List<Destination> toasts = destinationService.queryDesByParentId(qo.getParentId());
        model.addAttribute("toasts",toasts);

        return "destination/list";
    }

    // 修改简介
    @RequestMapping("updateInfo")
    @ResponseBody
    public Object updateInfo(Destination destination) {

        destinationService.update(destination);

        return JsonResult.success();
    }


}
